<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>微信扫码登录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${request.contextPath}/static/libs/layui/css/layui.css" media="all">
    <style>
        #wechat_login_error_container {
            text-align: center;
            padding-top: 36px;
            height: 367px;
        }

        #wechat_login_error_header {
            margin-bottom: 30px;
        }

        .zlui-icon-wechat-msg-success:before {
            font-size: 95px;
            color: #09BB07;
        }

        .zlui-icon-wechat-msg-warn:before {
            font-size: 95px;
            color: #F43530;
        }

        .zlui-icon-wechat-msg-info:before {
            font-size: 95px;
            color: #10AEFF;
        }

        #wechat_login_error_body {
            color: black;
            margin-bottom: 25px;
            padding: 0 20px;
            line-height: 1.6;
        }

        #wechat_login_error_body h4 {
            display: block;
            margin-block-start: 1.33em;
            margin-block-end: 1.33em;
            margin-inline-start: 0px;
            margin-inline-end: 0px;
            margin-bottom: 5px;
            font-weight: 400;
            font-size: 20px;
        }
    </style>
    <script src="${request.contextPath}/static/libs/layui/layui.js"></script>
</head>

<body id="zhengling-zhuye">
    <div class="layui-hide">
        <input type="hidden" name="state" value="${callback.state}" autocomplete="off">
        <input type="hidden" name="openid" value="${callback.openid}" autocomplete="off">
        <input type="hidden" name="orgcode" value="${callback.orgcode}" autocomplete="off">
        <input type="hidden" name="orgid" value="${callback.orgid}" autocomplete="off">
        <input type="hidden" name="RWID" value="${callback.RWID}" autocomplete="off">
        <input type="hidden" name="loginUrl" value="${callback.loginUrl}" autocomplete="off">
        <input value="${tokenidname}" type="hidden" name="tokenidname">
    </div>
    <div id="wechat_login_error_container" style="display: none;">
        <div id="wechat_login_error_header">
            <i class="zlui-icon zlui-icon-wechat-mgs zlui-icon-wechat-msg-info"></i>
        </div>
        <div id="wechat_login_error_body">
            <h4>扫码登录失败</h4>
        </div>
    </div>
    <script type="text/javascript">
        layui.config({
            version: "<@configVersion suosxt='CORE'> </@configVersion>"
            , base: '${request.contextPath}/static/framework/' //静态资源所在路径
            , contentPath: '${request.contextPath}'
        }).use(['zlConfig', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer
                , zlConfig = layui.zlConfig
                , statusName = zlConfig.global.result.statusName
                , msgName = zlConfig.global.result.msgName
                , dataName = zlConfig.global.result.dataName
                , ERROR = zlConfig.global.result.errorState
                , OK = zlConfig.global.result.okState;

            var layerIndex = layer.msg('正在登录中，请稍候...', { time: false, shade: [0.1, '#393D49'] });
            //需要操作的方法名
            var methodName = '${callback.methodName}';
            var callbackAction = {
                bind: function () {
                    var state = $('.layui-hide input[name="state"]').val();
                    var openid = $('.layui-hide input[name="openid"]').val();
                    var orgcode = $('.layui-hide input[name="orgcode"]').val();
                    //绑定
                    top.location.href = "${request.contextPath}/web/ssologin/wechat/bind?orgcode=" + orgcode + "&state=" + state + "&openid=" + openid;
                },
                login: function () {
                    //登录
                    var loginUrl = $('.layui-hide input[name="loginUrl"]').val();
                    if (!loginUrl) {
                        loginUrl = layui.cache['contentPath'] + "/" + orgcode;
                    }
                    var params = {
                        'openid': $('.layui-hide input[name="openid"]').val(),
                        'orgcode': $('.layui-hide input[name="orgcode"]').val(),
                        'orgid': $('.layui-hide input[name="orgid"]').val(),
                        'RWID': $('.layui-hide input[name="RWID"]').val(),
                        'loginUrl': loginUrl
                    }
                    var url = layui.cache['contentPath'] + "/web/ssologin/wechat/dologin";
                    $.ajax({
                        url: url,
                        type: 'post',
                        async: true,
                        data: JSON.stringify(params),
                        dataType: 'json',
                        contentType: "application/json",
                        success: function (ret) {
                            layer.close(layerIndex);
                            if (OK == ret[statusName]) {
                                layer.msg("登陆成功", { icon: 1, time: 5000 });
                                var userVo = ret[dataName];
                                var tokenidname = $('.layui-hide input[name="tokenidname"]').val();
                                setTimeout(function () {
                                    top.location.href = layui.cache['contentPath'] + '/index/?' + tokenidname + "=" + userVo["tokenId"];
                                }, 800);
                            } else {
                                callbackAction.showMsg(ret[msgName]);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.close(layerIndex);
                            if (textStatus == "404") {
                                layer.msg("请求地址出错!", { icon: 2, time: 5000 });
                            } else if (textStatus == "302") {
                                layer.msg('连接网页出错!', { icon: 2, time: 5000 });
                            } else if (textStatus == "timeout") {
                                layer.msg("请求超时!", { icon: 2, time: 5000 });
                            } else {
                                layer.msg('请求异常!', { icon: 2, time: 5000 });
                            }
                            callbackAction.showMsg('扫码登录失败');
                        }
                    });
                },
                showMsg: function (param) {
                    layer.close(layerIndex);
                    var msg = param || "${callback.msg}";
                    msg = msg || "扫码登录失败";
                    //展示信息
                    // layer.msg(msg, { icon: 2, time: 5000 });
                    $('#wechat_login_error_body h4').text(msg);
                    $('#wechat_login_error_container').fadeIn('fast');
                }
            }
            //执行回调
            if (methodName && callbackAction[methodName]) {
                callbackAction[methodName].call(this);
            }
        });
    </script>
</body>

</html>